package com.wxzz.elearing.livetelecast.api.app;

import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.livetelecast.dto.*;
import com.wxzz.elearing.livetelecast.entity.Activity;
import com.wxzz.elearing.livetelecast.entity.ActivityCategory;
import com.wxzz.elearing.livetelecast.entity.PlatformLivetelecast;
import com.wxzz.elearing.livetelecast.entity.WxUserPlatformLivetelecast;
import com.wxzz.elearing.livetelecast.service.IActivityService;
import com.wxzz.elearing.livetelecast.service.IPlatformLivetelecastService;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import retrofit2.http.Multipart;

import java.util.List;

@RestController
@RequestMapping("/wx-activity")
@Api(tags = "活动接口(小程序)")
public class WxActivityController {

    @Autowired
    private IActivityService activityService;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @ApiOperation(value = "活动列表(小程序)", notes = "活动列表(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "listActivity", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<Activity>>> listActivity(@RequestBody WxActivityDto wxActivityDto) {
        return activityService.listActivity(wxActivityDto);
    }

    @ApiOperation(value = "查询活动详情(小程序)", notes = "查询活动详情(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "selectActivityById/{activityId}", method = RequestMethod.POST)
    public ReturnVO<Activity> selectActivityById(@RequestHeader String token, @PathVariable("activityId") Long activityId) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return activityService.selectActivityById(jsonObject.getLong("id"), activityId);
    }

    @Autowired
    private IPlatformLivetelecastService platformLivetelecastService;

    @ApiOperation(value = "展示我预约的活动(小程序)", notes = "展示我预约的活动(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "listMyActivity", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<Activity>>> listMyActivity(@RequestHeader String token, @RequestBody MyWxPlatformLivetelecastDto myWxPlatformLivetelecastDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return platformLivetelecastService.listMyActivity(jsonObject.getLong("id"), myWxPlatformLivetelecastDto);
    }

    @ApiOperation(value = "活动分类列表(小程序)", notes = "活动分类列表(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "listActivityCategory", method = RequestMethod.POST)
    public ReturnVO<List<ActivityCategory>> listActivityCategory() {
        return activityService.listActivityCategory();
    }

    @ApiOperation(value = "活动详情报名列表(小程序)", notes = "活动详情报名列表(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "listWxUserPlatformLivetelecast", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<WxUserPlatformLivetelecast>>> listWxUserPlatformLivetelecast(@RequestBody WxInPlatformLivetelecastDto wxInPlatformLivetelecastDto) {
        return activityService.listWxUserPlatformLivetelecast(wxInPlatformLivetelecastDto);
    }

    @ApiOperation(value = "活动预约(小程序)", notes = "活动预约(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "saveWxUserPlatformLivetelecast4activity", method = RequestMethod.POST)
    public ReturnVO<PlatformLivetelecast> saveWxUserPlatformLivetelecast4activity(@RequestHeader String token, @RequestBody WxUserPlatformLivetelecast4activityDto wxUserPlatformLivetelecast4activityDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return activityService.saveWxUserPlatformLivetelecast4activity(jsonObject, wxUserPlatformLivetelecast4activityDto);
    }

    @ApiOperation(value = "活动签到(返回座位号 0为没座位号 -1未未支付)(小程序)", notes = "活动签到(小程序)", httpMethod = "POST", tags = "小程序")
    @RequestMapping(value = "activitySignIn/{activityId}", method = RequestMethod.POST)
    public ReturnVO activitySignIn(@RequestHeader String token, @PathVariable Long activityId) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        return activityService.activitySignIn(jsonObject.getLong("id"), activityId);
    }


}
